#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
bool check(int year){
    if(year%4==0 && year%100!=0 || year%400==0){
        return true;
    }
    else{
        return false;
    }
}
int main(void){
    int n;
    int year,month,day;
    scanf("%d",&n);
    while(n--){
        scanf("%d-%d-%d",&year,&month,&day);
        int ans=0;
        if(month==2 && day==29){
            printf("-1\n");
            continue;
        }
        if(month<3){
            for(int i=0;i<18;i++){
                if(check(year+i)){
                    ans+=366;
                }
                else{
                    ans+=365;
                }
            }
        }
        else{
            for(int i=1;i<=18;i++){
                if(check(year+i)){
                    ans+=366;
                }
                else{
                    ans+=365;
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}
